#!/bin/sh
# Job yaml can send below ENVIRONMENT VARIABLES to me
# - interval
# END ENVIRONMENT VARIABLES

[ -f /sys/devices/system/cpu/cpu0/cpuidle/state0/name ] || exit 0

take_snapshot()
{
	echo time: $(date +%s.%N)

	for dir in /sys/devices/system/cpu/cpu*/cpuidle/state*/
	do
		cpu=${dir#/sys/devices/system/cpu/}
		cpu=${cpu%%/*}
		state_name=$(sed 's/ /-/g' $dir/name)
		read state_time  < $dir/time
		read state_usage < $dir/usage
		echo $cpu.${state_name}.time: ${state_time}
		echo $cpu.${state_name}.usage: ${state_usage}
	done
}

file=$(basename $0)

. $LKP_SRC/lib/wait.sh
setup_wait

if [ -z "$interval" ]; then
	take_snapshot
	wait_post_test
	take_snapshot
	exit
fi

while :
do
	take_snapshot
	wait_timeout $interval
done
